<template>
	<view class="flex-col page">
		<view>
			<view :style="{height:statusBarHeight+'px'}"></view>
			<u-navbar title="我的钱包" bgColor="#E6EFFF" @leftClick="$nav(2)">	
			</u-navbar>
		</view>
		
		<view class="flex-col top-bg">
			
			<view class="top-text">
				<view class="flex-col">
					
					<view class="flex-row items-center" @click="yundouClick">
						<text>云豆</text>
						<u-icon name="question-circle" size="18" color="#fff" style="margin-left: 10rpx;"></u-icon>
					</view>
					<text style="font-size: 50rpx;margin-top: 10rpx;">{{cloud_bean}}</text>
				</view>
				
				<view class="in-btn" @click="$nav(1,'/pages/wallet/recharge?tip=1')">充值</view>
			</view>
			<view class="line2"></view>
			<view class="flex-row justify-between items-center" style="padding: 50rpx;color: #fff;">
				<view class="flex-col items-center">
					<view class="flex-row items-center" @click="birClick">
						<text>生日豆</text>
						<u-icon name="question-circle" size="18" color="#fff" style="margin-left: 10rpx;"></u-icon>
					</view>
					
					<text style="margin-top: 10rpx;font-size: 40rpx;">{{birth_bean}}</text>
				</view><view class="flex-col items-center">
					
					<view class="flex-row items-center" @click="ruralClick">
						<text>帮扶豆</text>
						<u-icon name="question-circle" size="18" color="#fff" style="margin-left: 10rpx;"></u-icon>
					</view>
					<text style="margin-top: 10rpx;font-size: 40rpx;">{{assist_bean}}</text>
				</view>
			</view>
			
		</view>
		
		
		
		
		<view class="list-bg">
			<view>账户记录</view>
			
			
		    <view class="flex-col" v-if="list.length > 0">
				<view class="flex-col" v-for="(item,index) in list" :key="index">
					<view class="fund-item">
						<view class="flex-col">
							<text style="font-size: 28rpx;">{{item.data_remarks}}</text>
							<text style="font-size: 26rpx;color: #999;margin-top: 15rpx;">{{item.date_time}}</text>
						</view>
						<view class="flex-col items-end">
							<text style="font-size: 28rpx;">{{getShowType(item)}}</text>
							<text style="font-size: 26rpx;color: #999;margin-top: 15rpx;">类型：{{item.payment}}</text>
						</view>
					</view>
					
					<view class="line"></view>
				</view>
			
				
				<u-loadmore margin-top="20" margin-bottom="20" :status="status" icon-type="flower"
					:load-text="loadText" />
			</view>
			
			
			<view v-else class="flex-col items-center" style="margin-top: 80rpx;">
				<image src="/static/data_empty.png"></image>
				<text style="color: #c0c4cc;">暂无数据</text>
				<!-- <u-empty margin-top='120' mode="history" text="暂无数据"></u-empty> -->
			</view>
			
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				page:1,
				status: 'loadmore',
				loadText: {
					loadmore: '下拉加载更多...',
					loading: '加载中...',
					nomore: '没有更多数据了...'
				},
				list:[],
				cloud_bean:0,
				birth_bean:0,
				assist_bean:0
			};
		},
		computed:{
			statusBarHeight(){
				return this.$store.state.statusBarHeight + 44
			}
		},
		onShow() {
			this.list = [];
			this.page = 1;
			this.getfundsList();
			this.getUserInfo();
		},
		onPullDownRefresh() {
			this.list = [];
			this.page = 1;
			this.getfundsList();
		},
		onReachBottom() {
			this.getfundsList();
		},
		methods:{
			yundouClick(){
				uni.showToast({
					icon:'none',
					title:'云豆支持购买任意商品',
					duration:3000
				})
			},
			birClick(){
				uni.showToast({
					icon:'none',
					title:'生日豆仅支持购买生日专区商品',
					duration:3000
				})
			},
			ruralClick(){
				uni.showToast({
					icon:'none',
					title:'帮扶豆仅支持购买帮扶专区商品',
					duration:3000
				})
			},
			
			getShowType(item){
				if(item.update_type == 1){
					return '+'+item.balance
				}else{
					return '-'+item.balance
				}
			},
			
			getUserInfo(){
				this.$request({
					url:'?c=User&a=info',
					type:'get',
				}).then(res =>{
					this.cloud_bean = res.data.cloud_bean;
					this.birth_bean = res.data.birth_bean;
					this.assist_bean = res.data.assist_bean;
				})
			},
			getfundsList(){
				this.$request({
					url:'?c=User&a=funds',
					type:'post',
					data:{
						page:this.page,
						limit:10
					}
				}).then(res =>{
					uni.stopPullDownRefresh();
					this.status = 'loadmore';
					if (res.data && res.data.length > 0) {
						this.list = [...this.list, ...res.data];
						this.page += 1;
						if (res.data.length < 10) {
							this.status = 'nomore';
						}
					} else {
						this.status = 'nomore';
					}
				})
			}
		}
	}
</script>

<style lang="scss">
.page{
	width: 100%;
	overflow-y: auto;
	overflow-x: hidden;
	height: 100%;
	background-color: #E6EFFF;
}
.top-bg{
	background-image: url("https://ysmz.scmzhc.com/static/mini/images/user/wallet_top_bg.png");
	background-size: cover;
	background-position: center;
	background-repeat: no-repeat;
	margin-left: 20rpx;
	margin-right: 20rpx;
	border-radius: 10rpx;
}
.top-text{
	display: flex;
	flex-direction: row;
	justify-content: space-between;
	padding: 50rpx;
	// height: 200rpx;
	color: #fff;
	align-items: center;
}
.in-btn{
	background-color: #93B7FF;
	border-radius: 40rpx;
	padding: 10rpx 30rpx;
	color: #fff;
}
.list-bg{
	background-color: #fff;
	border-radius: 10rpx;
	margin: 20rpx;
	min-height: 80vh;
	padding: 20rpx;
}
.fund-item{
	display: flex;
	flex-direction: row;
	justify-content: space-between;
	margin-top: 30rpx;
}
.line{
	border: 1px solid #f5f5f5;
	margin-top: 25rpx;
}
.line2{
	border: 1rpx solid #f5f5f5;
	
	margin-left: 50rpx;
	margin-right: 50rpx;
}
</style>
